$(function(){
	
//	主模块
	var vm = new Vue({
		el:'#doumee',
		data:{
			caseData:data.case,
			goodData:data.product,
			activeData:data.active,
			wealData:data.weal,
			articleData:data.article,
			pushType:0,
			kitchenArr:data.kitchenScreen,
			homeArr:data.caseScreen,
			arr:[],
			sel:[0,0,0],
			type:0,
			list:null,
			spec:['价格降序','价格升序','销量降序'],
			radioVal:''
		},
		methods:{
			//案例-多选推送
//			checkCase:function(e){
//				var num = 0;
//				$("#Main .checkBox:checked").each(function(){
//					num++;
//				});
//				totalNum(num);
//			},
			
			//商品-单项推送
//			send:function(id){
//				console.log(id)
//			},
			
			//收放优惠券详情
			controlRuler:function(e){
				var node = e.currentTarget.children;
				if(node[1].className.indexOf('active') < 0){
					//展开
					node[0].className = 'flex-full ruler animate';
					node[1].className = 'btn animate active';
				}else{
					//收起
					node[0].className = 'flex-full ruler animate dm-wrap';
					node[1].className = 'btn animate';
				};
			},
			
			//选择当前优惠券（确认订单模块）
			selCur:function(e){
				var target = e.currentTarget;
				$('.weal-box').removeClass('on');
				if(target.parentElement.className.indexOf('on') < 0){
					target.parentElement.className = 'weal-box on';
				};
			},
			
			//案例切换
			caseTab:function(type){
				console.log(type)
				this.type = type;
				this.sel = [0,0,0];
				this.getType();
				this.swiper.setWrapperTranslate(0);
				this.radioVal = '';
			},
			//判断type类型
			getType:function(){
				if(this.type==0){
					//厨柜
					this.arr = this.kitchenArr;
				}else{
					//全屋
					this.arr = this.homeArr;
				};
			},
			//打开多选
			check:function(){
				//打开多选项
				openSubMain('#screenMask');
			},
			//选项切换
			checkOpt:function(index,value){
				this.sel.splice(index,1,value);
			},
			//重置
			resetOpt:function(){
				this.sel = [0,0,0];
				closeSubMain($("#screenMask"));
			},
			//确认筛选
			enterOpt:function(){
				console.log(this.sel);
				closeSubMain($("#screenMask"));
			},
			
			//单项商品筛选
			screen:function(e,type){
				$("#screenMask").remove();
				var that = this;
				var target = e.currentTarget;
				
				if(type == 1){
					//综合排序
					$('#goodMod dl').eq(type).addClass('on').siblings().removeClass('on active');
				}else if(type == 2){
					//价格销量排序
					var node = $('#goodMod dl').eq(type);
					var arr = that.spec;
					var check = target.getAttribute('data-check');
					if(node.hasClass('on')){
						//选中
						if(node.hasClass('active')){
							//关闭
							$('#goodMod dl').eq(type).removeClass('active');
						}else{
							//打开
							$('#goodMod dl').eq(type).addClass('active');
							caseRadio(arr,check,function(index){
								target.setAttribute('data-check',index);
								target.children[0].innerHTML = that.spec[index];
								target.className = 'flex-full flex-row on';
							});
						};
					}else{
						//未选中
						$('#goodMod dl').eq(type).addClass('on').siblings().removeClass('on');
					};
				}else{
					//选择分类
					
					var check = '';
					that.list == null ? check = [0,0,0] : check = that.list;
					createAreaPick(function(arr){
						that.list = arr;
					},check);
				};
				
			},
			
		},
		created:function(){
			var that = this;
			var type = getUrlParam('type');
			type != null ? type : type = 0;
			if(type != 0){$("#screenMod").remove()};
			
			if(type != 1){
				$("#goodMod").remove()
			}else{
				$("#pushMask").remove();
			};
			
			if(type != 3){$("#wealSpec").remove()};
			
			that.pushType = type;
			$("#pushNav a").eq(type).addClass('on');
			imgRate();
		},
		mounted:function(){
			this.getType();
			this.swiper = pullSwiper("#Main",{
				up:true,//启动下拉刷新,也可自定义函数，默认禁用
				down:true,//启用上拉加载,也可自定义函数，默认禁用
			});
			pullSwiper('#caseAllSel');
		},
		watch:{
			radioVal(val){
				console.log(val)
			}
		}
	});
	
	
	//优惠券
	$("#wealSpec li").click(function(){
		$(this).addClass('on').siblings().removeClass('on');
	});
	
});


//下拉刷新
function refresh(pull){
	pull.innerHTML='刷新完成';
	vm.radioVal
};

//上拉加载
function reload(pull){
	pull.innerHTML='已加载全部数据';
};

//推送类别切换
function pushTab(obj){
	var index = $(obj).index();
	location.replace('pushMod.html?type='+index);
};


//合计总数量
function totalNum(num){
	$("#totalVal").text(num);
};


//收放已选择列表
function showAllSel(){
	if($("#pushMask").is(':hidden')){
		$("#pushMask").show();
	}else{
		$("#pushMask").hide();
	};
};
